import './assets/main.css'
import 'nprogress/nprogress.css'
import '@imengyu/vue3-context-menu/lib/vue3-context-menu.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { setupRouter } from './router'
import { setupDirectives } from '@/directives'

import App from './App.vue'
import AppLoading from '@/components/app-loading.vue'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const setupAPP = async () => {
  // 刷新展示加载中
  const appLoading = createApp(AppLoading)
  appLoading.mount('#appLoading')

  // 创建app实例
  const app = createApp(App)
  // 将app实例挂载到全局配置，用于安装自定义指令等
  app.config.globalProperties.$appInstance = app

  // 安装状态管理器并做持久化
  const pinia = createPinia()
  pinia.use(piniaPluginPersistedstate)
  app.use(pinia)

  // 安装路由
  await setupRouter(app)
  // 安装自定义指令
  await setupDirectives(app)

  app.mount('#app')
}

setupAPP().then(() => {})
